/*
 * @Author: zpz
 * @Date: 2019-04-26 17:32:37
 * @LastEditors: Bingo
 * @Email: 13714943895@163.com
 */
import { constantRouterMap } from "@/route/route_list/index";
/**
 * 过滤账户是否拥有某一个权限，并将菜单从加载列表移除
 *
 * @param permission
 * @param route
 * @returns {boolean}
 */
/**
 * 单账户多角色时，使用该方法可过滤角色不存在的菜单
 *
 * @param roles
 * @param route
 * @returns {*}
 */

const permission = {
  namespaced: true,
  state: {
    // 静态路由表
    routers: constantRouterMap,
    // 动态路由表
    addRouters: [],
    layoutRouter: [],
  },
  mutations: {
    SET_ROUTERS: (state: { addRouters: any; routers: any[] }, routers: any) => {
      state.addRouters = routers;
      // 静态路由表 + 动态路由表 = 系统所有的路由表
      state.routers = constantRouterMap.concat(routers);
    },
    LAYOUT_ROUTER: (state: { layoutRouter: any }, layoutRouter: any) => {
      state.layoutRouter = layoutRouter;
    },
  },
  actions: {
    GenerateRoutes({ commit }: any, data: { Router: any }) {
      return new Promise<void>((resolve) => {
        commit("SET_ROUTERS", data.Router);
        resolve();
      });
    },
  },
};

export default permission;
